{extend name="public:adminbase" /}

{block name="content"}

<div class="container-fluid p-t-15">
  
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-toolbar clearfix">
          <form class="pull-right search-bar" method="get" action="#!" role="form">
            <div class="input-group">
              <div class="input-group-btn">
                <input type="hidden" name="search_field" id="search-field" value="title">
                <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                标题 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                  <li> <a tabindex="-1" href="javascript:void(0)" data-field="title">标题</a> </li>
                  <li> <a tabindex="-1" href="javascript:void(0)" data-field="cat_name">栏目</a> </li>
                </ul>
              </div>
              <input type="text" class="form-control" value="<?php if(request()->param('keyword')){echo request()->param('keyword');}?>" name="keyword" placeholder="请输入名称">
            </div>
          </form>
          <div class="toolbar-btn-action">
            <button class="btn btn-primary m-r-5" onclick="AddCate(this)" href="{:url('create')}"><i class="mdi mdi-plus"></i> 新增</button>

            <!--<a class="btn btn-success m-r-5" href="#!"><i class="mdi mdi-check"></i> 启用</a>-->
            <!--<a class="btn btn-warning m-r-5" href="#!"><i class="mdi mdi-block-helper"></i> 禁用</a>-->
            <!--<a class="btn btn-danger" href="#!"><i class="mdi mdi-window-close"></i> 删除</a>-->
            <button class="btn btn-success m-r-5" onclick="location.reload()" ><i class="mdi mdi-refresh"></i> 刷新本页</button>
          </div>
        </div>
        <div class="card-body">
          
          <div class="table-responsive">
            <table class="table table-bordered" id="example-advanced">
              <thead>
                <tr>
                  <th>
                    <label class="lyear-checkbox checkbox-primary">
                      <input type="checkbox" id="check-all"><span></span>
                    </label>
                  </th>
                  <th>code</th>
                  <th>类型</th>
                  <th>version</th>
                  <th>链接</th>
                  <th>是否启用</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>

                {foreach $list as $k=> $v}
                <tr >
                  <td>
                    <label class="lyear-checkbox checkbox-primary">
                      <input type="checkbox" name="ids[]" value="{$v.id}"><span></span>
                    </label>
                  </td>
                  <td>{$v.code}</td>
                  <td>{$v.type}</td>
                  <td>{$v.version}</td>
                  <td>{$v.url}</td>
                  <td>
                    {switch $v.status}
                    {case 1 }<button class="btn btn-label btn-primary btn-xs">已启用</button>{/case}
                    {case 2 }<button class="btn btn-label btn-warning btn-xs">已禁用</button>{/case}
                    {default /}<button class="btn btn-label btn-primary btn-xs">已启用</button>
                    {/switch}
                  </td>
                  <td>
                    <div class="btn-group">
                      <button onclick="edit(this)" class="btn btn-xs btn-default" href="{:url('edit',['id'=>$v.id])}" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></button>
                      <button onclick="del({$v.id})" class="btn btn-xs btn-default" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></button>
                    </div>
                  </td>
                </tr>
                {/foreach}

              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
    
  </div>
  
</div>
{include file="public/afooter"}
<script>
//  新增
  function AddCate(obj) {
    var url = $(obj).attr('href');
    layer.open({
      title:"新增分类",
      type: 2,
      area: ['500px', '800px'],
      fixed: false, //不固定
      maxmin: true,
      content: url
    });
  }
//修改
  function edit(obj) {
    var url = $(obj).attr('href');
    layer.open({
      title:"修改",
      type: 2,
      area: ['500px', '450px'],
      fixed: false, //不固定
      maxmin: true,
      content: url
    });
  }
//  删除
  function del(id) {
    layer.confirm('您确定要删除吗？', {
      btn: ['确定','取消'] //按钮
    }, function(){
      var url = "{:url('delete')}"
      $.post(url,{id:id},function (e) {
        if(e.code != 200){
          error(e.msg);
        }else {
          success(e.msg);
          var index = parent.layer.getFrameIndex(window.name);
          setTimeout(function(){parent.layer.close(index)}, 1000);
          window.parent.location.reload();
        }
      })
    }, function(){
      layer.msg('已取消');
    });
  }

</script>

{/block}